<?php
namespace Home\Controller;

class DoctorController extends CommonController{
    
    //患者查看医生主页
    public function index($id){
        $vo = M('User')->find($id);
        $hptRow = M('Hospital')->find($vo['hpt_id']);
        $vo['htp_name'] = $hptRow['name'];
        $this->assign('vo',$vo);
        
        $this->assign('userInfo',M('User')->find($this->uid));
        $this->display();
    }
    
    //患者查看营养师主页
    public function indexn($id){
        $vo = M('User')->find($id);
        $this->assign('vo',$vo);
        $this->assign('userInfo',M('User')->find($this->uid));
        $this->display();
    }
    
    //医生列表
    public function lists(){
        $User = M('User');
        $userInfo = $User->find($this->uid);
        $this->assign('userInfo',$userInfo);
        
        $myDocArr = array();//我关联的医生
        $list = array();//所属透析中心下非我关注的医生列表
        
        if(empty($userInfo['uid'])) $userInfo['uid'] = 0;
        $myDocArr = $User->where(array('id'=>$userInfo['uid'],'type'=>'1'))->select();
        $list = $User->where(array('id'=>array('NEQ',$userInfo['uid']),'type'=>'1','hpt_id'=>$userInfo['hpt_id']))->select();
        
        $this->assign('list',array_merge($myDocArr,$list));
        $this->display();
    }
    
    //营养师列表
    public function nlists(){
        $User = M('User');
        $userInfo = $User->find($this->uid);
        $this->assign('userInfo',$userInfo);
        
        $myDocArr = array();//我关联的
        $list = array();//非我关联的
        
        if(empty($userInfo['nid'])) $userInfo['nid'] = 0;
        $myDocArr = $User->where(array('id'=>$userInfo['nid'],'type'=>'3'))->select();
        $list = $User->where(array('id'=>array('NEQ',$userInfo['nid']),'type'=>'3'))->select();
        
        $this->assign('list',array_merge($myDocArr,$list));
        $this->display();
    }
    
    //医生自己的主页
    public function info(){
        $User = M('User');
        $userInfo = $User->find($this->uid);
        $hptRow = M('Hospital')->find($userInfo['hpt_id']);
        $userInfo['hpt_name'] = $hptRow['name'];
        $this->assign('userInfo',$userInfo);
        $this->display();
    }
    
    //医生修改简介
    public function saveDes(){
        M('User')->save(array('id'=>I('post.id'),'des'=>I('post.des')));
    }
    
    //关联医生操作
    public function actLink(){
        M('User')->save(array('id'=>$this->uid,'uid'=>I('post.uid')));
    }
    
    //关联营养师操作
    public function actLinkN(){
        M('User')->save(array('id'=>$this->uid,'nid'=>I('post.nid')));
    }
    
}